#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    bool canConstruct(string ransomNote, string magazine)
    {
        unordered_map<char, int> s;
        for (auto e : magazine)
        {
            ++s[e];
        }
        for (auto e : ransomNote)
        {
            if (s.find(e) == s.end())
            {
                return false;
            }
            else
            {
                s[e]--;
                if (s[e] < 0)
                {
                    return false;
                }
            }
        }
        return true;
    }
};